home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Topik / Topik - Disk 16 - KnowAboutIt (19xx)(Topik Public Domain)(PD)[WB].zip / Topik - Disk 16 - KnowAboutIt (19xx)(Topik Public Domain)(PD)[WB].adf / MicroRayDbw / uray.h < prev    next >
C/C++ Source or Header  |  1988-12-11  |  10KB  |  368 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *            Copyright (c) 1988, David B. Wecker            *
  4.  *                All Rights Reserved                *
  5.  *                                    *
  6.  * This file is part of DBW_uRAY                    *
  7.  *                                    *
  8.  * DBW_uRAY is distributed in the hope that it will be useful, but    *
  9.  * WITHOUT ANY WARRANTY. No author or distributor accepts        *
  10.  * responsibility to anyone for the consequences of using it or for    *
  11.  * whether it serves any particular purpose or works at all, unless    *
  12.  * he says so in writing. Refer to the DBW_uRAY General Public        *
  13.  * License for full details.                        *
  14.  *                                    *
  15.  * Everyone is granted permission to copy, modify and redistribute    *
  16.  * DBW_uRAY, but only under the conditions described in the        *
  17.  * DBW_uRAY General Public License. A copy of this license is        *
  18.  * supposed to have been given to you along with DBW_uRAY so you    *
  19.  * can know your rights and responsibilities. It should be in a file    *
  20.  * named COPYING. Among other things, the copyright notice and this    *
  21.  * notice must be preserved on all copies.                *
  22.  ************************************************************************
  23.  *                                    *
  24.  * Authors:                                *
  25.  *    DBW - David B. Wecker                        *
  26.  *                                    *
  27.  * Versions:                                *
  28.  *    V1.0 881023 DBW    - First released version            *
  29.  *    V1.1 881110 DBW - Fixed scan coherence code            *
  30.  *    V1.2 881125 DBW - Removed ALL scan coherence code (useless)    *
  31.  *              added "fat" extent boxes            *
  32.  *                                    *
  33.  ************************************************************************/
  34.  
  35. #define VERSION "uRAY v1.2 881125 (C) 1988 D. Wecker - all rights reserved\n"
  36.  
  37. /************************************************************************/
  38. /************* global definitions for uray software *********************/
  39. /************************************************************************/
  40.  
  41. #ifdef URAY_MAIN
  42. #   define  MAINDEF
  43. #   define  MAINVAL(a)    = a
  44. #else
  45. #   define  MAINDEF    extern
  46. #   define  MAINVAL(a)
  47. #   endif
  48.  
  49.  
  50. /******************** include files **************************************/
  51.  
  52. #include <stdio.h>
  53. #include <math.h>
  54. #include <signal.h>
  55.  
  56. #ifdef U__X
  57. #include <sys/types.h>
  58. #include <sys/times.h>
  59. #endif
  60.  
  61. #ifdef VMS
  62. #include <types.h>
  63. #include <time.h>
  64. #endif
  65.  
  66. #ifdef AMIGA
  67. #ifndef SIGINT
  68. #   define  SIGINT  1
  69. #   endif
  70. #include <exec/types.h>
  71. #include <intuition/intuition.h>
  72. #endif
  73.  
  74.  
  75. /********************** floating point defs ******************************/
  76.  
  77. #if DODOUBLE
  78. #   define FLTDBL   double
  79. #   define MYHUGE   ((double)1.0e+30)
  80. #   define TOL        ((FLTDBL)1.0e-7)        /* minimum tolerance */
  81. #   ifdef AMIGA
  82. #    define BIGF
  83. #    endif
  84. #else
  85. #   define FLTDBL   float
  86. #   define MYHUGE   ((float)1.0e+17)
  87. #   define TOL        ((FLTDBL)1.0e-4)        /* minimum tolerance */
  88. #   endif
  89.  
  90. #ifdef BIGF
  91. #   define SCAN1    "%s %F"
  92. #   define SCAN2    "%s %F %F %F"
  93. #   define SCAN3    "%F %F %F %F %F %F %F %F %F %F %d %d %F %F %F %F %F %F"
  94. #   define SCAN4    "%F %F %F %F %F %F %F"
  95. #   define SCAN5    "%s %d %F %F %F %F"
  96. #   define SCAN6    "%s %d %F %F %F %F %F %F %F %F %F"
  97. #   define SCAN7    "%s %d %F %F %F %F %F %F %F %F %F %F %F"
  98. #else
  99. #   define SCAN1    "%s %f"
  100. #   define SCAN2    "%s %f %f %f"
  101. #   define SCAN3    "%f %f %f %f %f %f %f %f %f %f %d %d %f %f %f %f %f %f"
  102. #   define SCAN4    "%f %f %f %f %f %f %f"
  103. #   define SCAN5    "%s %d %f %f %f %f"
  104. #   define SCAN6    "%s %d %f %f %f %f %f %f %f %f %f"
  105. #   define SCAN7    "%s %d %f %f %f %f %f %f %f %f %f %f %f"
  106. #   endif
  107.  
  108. /********************** debug defs ****************************************/
  109.  
  110.  
  111. #define DEBUG_dumpnodes    0   /* dump a tree of all nodes and extents */
  112. #define DEBUG_ilbm    0   /* show ILBM output info */
  113. #define DEBUG_pixels    0   /* show pixel RGB values */
  114.  
  115.  
  116. /*********************** global defs **************************************/
  117.  
  118. #define MAXCOLS    1024                /* maximum compute width */
  119.  
  120. #define ABS(a)        (((a) < 0)   ? -(a) : (a))
  121. #define FABS(a)        (((a) < 0.0) ? -(a) : (a))
  122. #define MIN(a,b)    (((a) < (b)) ?  (a) : (b))
  123. #define MAX(a,b)    (((a) > (b)) ?  (a) : (b))
  124.  
  125. #define vdot(A,B)    (A[0]*B[0] + A[1]*B[1] + A[2]*B[2])
  126. #define vnorm(A)    sqrt(vdot(A,A))
  127. #define vcopy(A,B)    B[0]=A[0]; B[1]=A[1]; B[2]=A[2]
  128. #define vscale(v,A,B)    B[0]=(v)*A[0]; B[1]=(v)*A[1]; B[2]=(v)*A[2]
  129. #define vcomb(v,A,B,C)    C[0]=(v)*A[0]+B[0]; C[1]=(v)*A[1]+B[1]; C[2]=(v)*A[2]+B[2]
  130. #define vadd(A,B,C)    C[0]=A[0]+B[0]; C[1]=A[1]+B[1]; C[2]=A[2]+B[2]
  131. #define vsub(A,B,C)    C[0]=A[0]-B[0]; C[1]=A[1]-B[1]; C[2]=A[2]-B[2]
  132. #define vmul(A,B,C)    C[0]=A[0]*B[0]; C[1]=A[1]*B[1]; C[2]=A[2]*B[2]
  133. #define vdir(A,B,C)    vsub(B,A,C); vunit(C,C)
  134. #define vcross(A,B,C)    C[0]=(A[1] * B[2]) - (B[1] * A[2]); \
  135.             C[1]=(A[2] * B[0]) - (B[2] * A[0]); \
  136.             C[2]=(A[0] * B[1]) - (B[0] * A[1]);
  137.  
  138. /******************* ILBM file header defines *****************************/
  139.  
  140. #ifndef HIRES
  141. #   define HIRES    0x8000L
  142. #   endif
  143. #ifndef HAM
  144. #   define HAM        0x800L
  145. #   endif
  146. #ifndef LACE
  147. #   define LACE        0x4L
  148. #   endif
  149. #define DEPTH        6
  150. #define MAXBYTE        (cols >> 3)
  151. #define BMHDsize    20L            /* chunk sizes */
  152. #define CMAPsize    96L
  153. #define CAMGsize    4L
  154. #define BODYsize    (((long)rows)*((long)(MAXBYTE))*(long)(DEPTH))
  155. #define FORMsize    (BODYsize+CAMGsize+CMAPsize+BMHDsize+36L)
  156.  
  157.  
  158. /************************** object types *********************************/
  159.  
  160. #define TYP_E    0    /* extent */
  161. #define TYP_S    1    /* sphere */
  162. #define TYP_Q    2    /* quad */
  163. #define TYP_T    3    /* triangle */
  164. #define TYP_R    4    /* ring */
  165. #define TYP_L    5    /* light */
  166.  
  167.  
  168. /************************** typedefs **************************************/
  169.  
  170. typedef FLTDBL VEC[3];
  171.  
  172. typedef struct _ATT {
  173.     VEC            color;
  174.     FLTDBL        kd, ks, kt, ir, kl, dist, kf;
  175.     short        wave, tex;
  176.     VEC            p1,p2;
  177.     } ATT;
  178. typedef struct _WAVE {
  179.     VEC            cen;
  180.     FLTDBL        phase, length, damp, amp;
  181.     } WAVE;
  182. typedef struct _NODE {
  183.     struct _NODE    *next;
  184.     unsigned char   typ;
  185.     ATT            *att;
  186.     VEC            cen;
  187.     } NODE;
  188. typedef struct _EXTENT {
  189.     NODE        *next;
  190.     unsigned char   typ;
  191.     VEC            min,max;
  192.     NODE        *child;
  193.     } EXTENT;
  194. typedef struct _SPHERE {
  195.     NODE        *next;
  196.     unsigned char   typ;
  197.     ATT            *att;
  198.     VEC            cen;
  199.     FLTDBL        rad;
  200.     } SPHERE;
  201. typedef struct _QUAD {
  202.     NODE        *next;
  203.     unsigned char   typ;
  204.     ATT            *att;
  205.     VEC            p0, v1, v2;
  206.     } QUAD;
  207. typedef struct _TRIANGLE {
  208.     NODE        *next;
  209.     unsigned char   typ;
  210.     ATT            *att;
  211.     VEC            p0, v1, v2;
  212.     } TRIANGLE;
  213. typedef struct _RING {
  214.     NODE        *next;
  215.     unsigned char   typ;
  216.     ATT            *att;
  217.     VEC            p0, v1, v2;
  218.     FLTDBL        rad1,rad2;
  219.     } RING;
  220. typedef struct _LIGHT {
  221.     struct _LIGHT   *next;
  222.     NODE        *child;
  223.     } LIGHT;
  224.  
  225.  
  226. /*************************** routines ***********************************/
  227.  
  228. char        *malloc(),
  229.         *calloc(),
  230.         *my_malloc(),
  231.         *my_calloc();
  232. void        leave(),
  233.         vunit(),
  234.         planenormal(),
  235.         spherenormal(),
  236.         gettex(),
  237.         getamb(),
  238.         getlights(),
  239.         getspecular(),
  240.         gettrans(),
  241.         readinput(),
  242.         wfil(),
  243.         unionvector(),
  244.         unionextent(),
  245.         getextent(),
  246.         doextents(),
  247.         dumpnodes(),
  248.         coutputs(),
  249.         woutputs(),
  250.         trace(),
  251.         calcripple();
  252. short        rfil(),
  253.         PackRow();
  254. NODE        *intersection(),
  255.         *intersection2(),
  256.         *hitextent(),
  257.         *hitsphere(),
  258.         *sortext(),
  259.         *doalloc(),
  260.         *srtext();
  261. FLTDBL        rnd(),
  262.         findnormal();
  263. long        random();
  264.  
  265.  
  266.  
  267. /*************************** variables ***********************************/
  268.  
  269. MAINDEF long        seed        MAINVAL(257);
  270. MAINDEF char        str[256],
  271.             cmd[256],
  272.             *basnam        MAINVAL("uray");
  273. MAINDEF char        *TYPstr        MAINVAL("ESQTRLF");
  274. MAINDEF VEC        NEAR
  275. #ifdef URAY_MAIN
  276.                 = {0.0, 0.0, 1.0}
  277. #endif
  278.                 ;
  279. MAINDEF VEC        FAR        
  280. #ifdef URAY_MAIN
  281.                 = {0.0, 0.0, 1.0}
  282. #endif
  283.                 ;
  284. MAINDEF VEC        GROUND        
  285. #ifdef URAY_MAIN
  286.                 = {0.6, 0.3, 0.3}
  287. #endif
  288.                 ;
  289. MAINDEF VEC        BLACK        
  290. #ifdef URAY_MAIN
  291.                 = { 0.0, 0.0, 0.0 }
  292. #endif
  293.                 ;
  294. MAINDEF VEC        from,
  295.             direction,
  296.             dirinv;
  297. MAINDEF NODE        *nodes        MAINVAL(NULL);
  298. MAINDEF FILE        *fp        MAINVAL(NULL);
  299. MAINDEF FILE        *fp2        MAINVAL(NULL);
  300. MAINDEF unsigned char    outary[3][MAXCOLS];
  301. MAINDEF short        rows        MAINVAL(400);
  302. MAINDEF short        startrow    MAINVAL(0);
  303. MAINDEF short        endrow        MAINVAL(400);
  304. MAINDEF short        cols        MAINVAL(320);
  305. MAINDEF short        bpp        MAINVAL(12);
  306. MAINDEF short        sline;
  307. MAINDEF short        obpsl;
  308. MAINDEF short        aov        MAINVAL(90);
  309. MAINDEF short        depth        MAINVAL(20);
  310. MAINDEF int        natts        MAINVAL(0);
  311. MAINDEF ATT        *atts        MAINVAL(NULL);
  312. MAINDEF int        nwaves        MAINVAL(0);
  313. MAINDEF WAVE        *waves        MAINVAL(NULL);
  314. MAINDEF int        row,
  315.             col;
  316. MAINDEF int        fnhits        MAINVAL(0),
  317.             gnhits        MAINVAL(0),
  318.             fehits        MAINVAL(0),
  319.             gehits        MAINVAL(0);
  320. MAINDEF EXTENT        *ext;
  321. MAINDEF SPHERE        *sph;
  322. MAINDEF QUAD        *qua;
  323. MAINDEF TRIANGLE    *tri;
  324. MAINDEF RING        *rin;
  325. MAINDEF LIGHT        *lights        MAINVAL(NULL);
  326. MAINDEF int        extcnt        MAINVAL(0);
  327. MAINDEF int        objcnt        MAINVAL(0);
  328. MAINDEF FLTDBL        aspect        MAINVAL(0.544);
  329. MAINDEF FLTDBL        base        MAINVAL(0.25);
  330. MAINDEF long        lng,
  331.             pos1,
  332.             pos2,
  333.             pos3,
  334.             lsize;
  335. MAINDEF short        wrd;
  336. MAINDEF unsigned char    byt;
  337. MAINDEF int        lstcolor    MAINVAL(0);
  338. MAINDEF unsigned char    colors[16][3];
  339. MAINDEF long        randtbl[ 63 ]
  340. #ifdef URAY_MAIN
  341.             = {
  342.             0x00000001, 0x41c67ea6, 0x967eb0e7,
  343.             0x2781e494, 0xc46b9b3d, 0xf94bdf32, 0x95fb7483,
  344.             0xd9e2b600, 0x9cfbae39, 0xbf54bc7e, 0x0ff6d5df,
  345.             0x0abd322c, 0x31dff4f5, 0x237c228a, 0xaf1cf0fb,
  346.             0x7de14518, 0xc487eb71, 0xe201dd56, 0xd2bfa1d7,
  347.             0xe2319ac4, 0xe3decdad, 0xe95678e2, 0x93728473,
  348.             0x500f9f30, 0x284797a9, 0x2c67412e, 0x7566f4cf,
  349.             0x42877e5c, 0xb3590565, 0x4daa423a, 0xe4880eeb,
  350.             0xf73c2448, 0xef5992e1, 0xeeea4806, 0x5656aec7,
  351.             0xe1133cf4, 0xca7b7c1d, 0x31d2de92, 0xad857063,
  352.             0x99a13460, 0x69d8bd19, 0xb53c51de, 0x3b54afbf,
  353.             0x7d55368c, 0x102f11d5, 0x1b37adea, 0x7aae88db,
  354.             0xde652f78, 0xb45bf651, 0xe3dabeb6, 0x6102d7b7,
  355.             0x7a79cb24, 0x8398a68d, 0x28cc1042, 0xe0e33853,
  356.             0x9f1a7590, 0x4b761e89, 0x858eee8e, 0xfa5f06af,
  357.             0x28d95abc, 0x87991a45, 0x388f659a, 0x751f5ecb }
  358. #endif
  359.             ;
  360.  
  361. MAINDEF long    *fptr            MAINVAL(&randtbl[ 2 ]);
  362. MAINDEF long    *rptr            MAINVAL(&randtbl[ 0 ]);
  363. MAINDEF long    *end_ptr        MAINVAL(&randtbl[ 63 ]);
  364.  
  365. #ifdef AMIGA
  366.     MAINDEF struct IntuitionBase *IntuitionBase;
  367. #   endif
  368.